package com.zthz.douxing


class CityInfoService {
    def cityCodeMap = [:] //用于存储 城市名 - 城市code map
    def codeCityMap = [:] //城市code - 城市名
    def cityCode = [:]

    def getCodeByCityCode(cityCode){
        def code = cityCodeMap[cityCode]
        if(!code){
            def selectCity =  CityInfo.findByCityCode(cityCode,[cache:true])
            cityCodeMap[cityCode] = selectCity?.code
            //codeCityMap[selectCity?.code]
            code = selectCity?.code
        }
        return code
    }

    def getNameByCode(cityCode){
        def cityName = codeCityMap[cityCode]
        if(!cityName){
            def selectCity =  CityInfo.findByCode(cityCode,[cache:true])
            codeCityMap[selectCity?.code] = selectCity?.nameCn
            cityName = selectCity?.nameCn
        }
        return cityName
    }

    def getAllCityInfo(){
        if(cityCode.size() == 0){
            cityCode = CityInfo.list()
        }
        return cityCode
    }


}
